<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class ListAll extends My_Controller {
    
    private $_catid;
    private $_limithotnews = 12;
    private $_objCI;
    
    public function __construct() {
        parent::__construct();
        //Default
//        $this->_catid = $_GET['cid'];
        $this->_catid = 8;

    }

    /**
     * Index Page for this controller.
     */
    public function index() {
        $CI = & get_instance();

        $cat_parentid = $this->_catid;
        $CI->load->model('frontend/category_model', 'Category', TRUE);
        $CI->load->model('frontend/article_model', 'Article', TRUE);
        $_arrCat = $CI->Category->sec_GetCategoryByParrent(array('catid' => $cat_parentid));
        $arrCatID = array();
        foreach ($_arrCat as $val) {
            $arrCatID[] = $val->id;
        }

        //Block hot news
//        $this->block_hotnews($arrCatID, $CI);

        // Block list news
        $this->block_listnews($arrCatID, $CI);
        
        //Add css into template
        $dataView['imageFrontPath'] = $this->_config['base_url'] . $this->_staticPathPublic . 'images';
        $this->template->parse_view('content', $this->_viewFront . 'list_view', $dataView);
        $this->template->render();
    }

    /**
     * @desc Get some new Article of some category
     * for 10 articles
     */
    public function block_hotnews($arrCatID, $CI) {
        $arrInput = array(
            'catid' => implode(',', $arrCatID),
            'limit' => $this->_limithotnews
        );
        $articles = $CI->Article->arc_lGetNewestByCatID($arrInput);
        echo '<pre>';
        print_r($articles);
        die;

        $i = 0;
        foreach ($articles as $art) {
            if ($i == 0) {
                $c->articles['hotnews1'] = $art;
            } else if ($i == 1) {
                $c->articles['hotnews2'] = $art;
            } else {
                $c->articles['hotnews3'][] = $art;
            }
            if ($i++ > 4)
                break;
        }
        $data['cate_result'] = $cate_result;
        $this->load->view($this->_config['front_path'] . 'newsbyobject_view', $data);
    }

    /**
     * @desc Block list news 
     */
    public function block_listnews($arrCatID, $CI) {
        $arrInput = array(
            'catid' => implode(',', $arrCatID),
            'limit' => 18
        );
        $articles = $CI->Article->arc_lGetNewestByCatID($arrInput);
        echo '<pre>';
        print_r($articles);
        die;
    }


}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */